package cn.wolfcode.qo;

import lombok.Getter;
import lombok.Setter;

import java.util.List;
@Getter
@Setter
public class PageResult<T> {

    private int currentpage;
    private int pageSize;

    private int totalCount;
    private List<T> listdata;
    private int totalpage;
    private int prevpage;
    private int nextpage;

    public PageResult(int currentpage, int pageSize, int totalCount, List<T> listdata) {
        this.currentpage = currentpage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.listdata = listdata;

        // 其他事计算出来的
        if (totalCount <= pageSize) {
            this.totalpage = 1;
            this.prevpage = 1;
            this.nextpage = 1;
            return;
        }

        this.totalpage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        this.prevpage = this.currentpage - 1 >= 1 ? this.currentpage - 1 : 1;
        this.nextpage = this.currentpage + 1 <= this.totalpage ? this.currentpage + 1 : this.totalpage;
    }
}
